<?php
/**
 *量体预约
 * @author 
 *
 */
class MeasureAction extends AdminAction
{
 	public function _initialize()
	{
		parent::_initialize();
	}
	 
	public function index()
    {
        $where="";
        if ($_REQUEST['phone']) {
            $where.=" phone ='".$_REQUEST['phone']."'";
        }      // echo $where;exit;
        $measure = M('order_measure'); // 实例化对象
        import("ORG.Util.Page");// 导入分页类
        $count = $measure->where($where)->count();// 查询满足要求的总记录数
        $Page = new Page($count, 20);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();// 分页显示输出
        $page=$_REQUEST['p']?$_REQUEST['p']:1;
        if ($_REQUEST['phone']) {

            $map = $_REQUEST['phone'];
            foreach ($map as $key => $val) {
                $Page->parameter .= "$key=" . urlencode($val) . '&';
            }
            $this->assign('phone',$_REQUEST['phone']);
        }

        $list = $measure->where($where)->order('dt_add desc')->page($page. ',20')->select();//print_r($list);
        $this->assign('pageShow',$show);// 赋值分页输出
        $this->assign('list',$list);// 赋值数据集
        $this->display('index');
	}
    
       //修改预定量体
    public function edit()
    {
        $id=intval($_GET['id']);
        $measure = M('order_measure'); // 实例化对象
        $row= $measure->where('id='.$id)->limit(1)->find();//print_r($row);exit;
        if($_POST['dosubmit']){
            unset($_POST['dosubmit']);
            if($_POST['store_id']==1){
                $_POST['address']="杭州市下城区长城街22号205";
            }else if($_POST['store_id']==2){
                $_POST['address']="杭州市西湖区教工路158-2号";
            }
            $_POST['arrival_time']=strtotime( $_POST['arrival_time']);
           if($measure->where('id='.$id)->save($_POST)){
            $this->success('修改成功!', url("measure/index"));
           }else{
            $this->error('修改失败!', url("measure/index"));
           }
          
        }else{
            $this->assign("row",$row);
            $this->display('edit');
        }
    }
    function measure_edit(){
        $user_measure_db = M('user_measure');
        $id=intval($_GET['id']);
        $measureInfo = $user_measure_db->where(array('id'=>$id))->find();
        $user_id=intval($_GET['user_id']);
        $order_id=intval($_GET['order_id']);
        if($_POST['dosubmit']){
            unset($_POST['dosubmit']);
            $measure_data = unserialize($measureInfo['measure_data']);
            $measure_data2 = unserialize($measureInfo['measure_data2']);
            //量体数据开始
            $measure_data['neck']['cm'] = $_POST['measure']['neck'];
            $measure_data['jacket_back']['cm'] = $_POST['measure']['jacket_back'];
            $measure_data['bicep']['cm'] = $_POST['measure']['bicep'];
            $measure_data['sleeve']['cm'] = $_POST['measure']['sleeve'];
            $measure_data['wrist']['cm'] = $_POST['measure']['wrist'];
            $measure_data['shirt']['cm'] = $_POST['measure']['shirt'];
            $measure_data['chest']['cm'] = $_POST['measure']['chest'];
            $measure_data['stomach']['cm'] = $_POST['measure']['stomach'];
            $measure_data['waist']['cm'] = $_POST['measure']['waist'];
            $measure_data['pants_hips']['cm'] = $_POST['measure']['pants_hips'];
            $measure_data['pants']['cm'] = $_POST['measure']['pants'];
            $measure_data['crotch']['cm'] = $_POST['measure']['crotch'];
            $measure_data['thigh']['cm'] = $_POST['measure']['thigh'];
            $measure_data['knee']['cm'] = $_POST['measure']['knee'];
            $measure_data['shoulder']['type'] = $_POST['measure']['shoulder'];
            $measure_data['chest_type']['type'] = $_POST['measure']['chest_type'];
            $measure_data['stomach_type']['type'] = $_POST['measure']['stomach_type'];
            $measure_data['posture']['type'] = $_POST['measure']['posture'];
            //量体数据结束
            $data = array(
                'measure_data' => serialize($measure_data),
                'measure_data2' => serialize($measure_data2),
               // 'measure_name' => $_POST['measure_name'],
                'weight' => $_POST['measure']['weight'],
                'height' => $_POST['measure']['height'],
                'age' => $_POST['measure']['age'],
                'clothes_size' => $_POST['clothes_size'],
                'pants_size' => $_POST['pants_size'],

                //量体数据开始
                'neck' => $_POST['measure']['neck'],
                'jacket_back' => $_POST['measure']['jacket_back'],
                'bicep' =>$_POST['measure']['bicep'],
                'sleeve' =>$_POST['measure']['sleeve'],
                'wrist' => $_POST['measure']['wrist'],
                'shirt' => $_POST['measure']['shirt'],
                'chest' =>$_POST['measure']['chest'],
                'stomach' => $_POST['measure']['stomach'],
                'waist' => $_POST['measure']['waist'],
                'pants_hips' => $_POST['measure']['pants_hips'],
                'pants' => $_POST['measure']['pants'],
                'crotch' => $_POST['measure']['crotch'],
                'thigh' => $_POST['measure']['thigh'],
                'knee' => $_POST['measure']['knee'],
               'shoulder' => $_POST['measure']['shoulder'],
               'chest_type' => $_POST['measure']['chest_type'],
               'stomach_type' => $_POST['measure']['stomach_type'],
               'posture' => $_POST['measure']['posture'],
                //量体数据结束
               'user_id'=>$_POST['user_id'],
                'm_status'=>1,
            );
            $_POST['m_status']=1;
            $last_id=MeasureModel::edit_measure_info($id,$data);
            if($last_id){
                $this->success('编辑成功！', U('order/order_edit/oid/'.$order_id), 'edit');
            }else{
                $this->error('编辑失败！', U('order/order_edit/oid/'.$order_id), 'edit');
            }
        }else{
            $measure_info=MeasureModel::get_measure_info($id);
            $this->assign("user_id",$user_id);
            $this->assign("measure_info",$measure_info);
            $this->display('measure_edit');
        }
    }
    function del(){
        $id=intval($_GET['id']);
        $weed= M("order_measure"); // 实例化对象
        if($weed->where('id='.$id)->delete()){
            $this->success('删除成功!', url("measure/index"));
        }else{
            $this->error('删除失败!', url("measure/index"));
        }
    }
   
}